package com.atguigu.controller;

import com.atguigu.entity.Permission;
import com.atguigu.service.PermissionService;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

/**
 * @title：
 * @author：Yu
 * @create：2023-03-02 17:15
 * @description：
 */
@Controller
@RequestMapping("/permission")
public class PermissionController {
    @DubboReference
    private PermissionService permissionService;

    @RequestMapping
    public String toIndex(Map map) {
        //查找所有的菜单
        List<Permission> all = permissionService.findAll();
        map.put("list", all);
        return "permission/index";
    }

    @RequestMapping("/create")
    public String create(Permission permission, Map map) {
        map.put("permission", permission);
        return "permission/create";
    }

    @RequestMapping("/save")
    public String save(Permission permission) {
        permissionService.insert(permission);
        return "common/success";
    }

    @RequestMapping("/edit/{permissionId}")
    public String edit(Map map, @PathVariable Long permissionId) {
        Permission byId = permissionService.findById(permissionId);
        map.put("permission", byId);
        return "permission/edit";
    }

    @RequestMapping("/update")
    public String update(Permission permission) {
        permissionService.update(permission);
        return "common/success";
    }

    @RequestMapping("/delete/{id}")
    public String delete(@PathVariable Long id) {
        permissionService.delete(id);
        return "redirect:/permission";
    }
}
